
/*====================================================================
project:       Generar tablas de diferentes samples para especificaciones
Author:        Diego Mayorga Córdova 
Dependencies:  Banco de México
----------------------------------------------------------------------
Creation Date:    29 Jul 2019 - 12:45:19
Modification Date:   
Do-file version:    01
References:          
Output:             tex
====================================================================*/

/*====================================================================
                        0: Program set up
====================================================================*/
version 15.1
drop _all
loc master 	"B:\Col_Minimum_Wage"
glo ster 	"`master'/Ster/rif10_new_indcc"
glo tablas	"`master'/Doc\tosubmit2\tab\cambio_sample"
loc master 	"B:\Col_Minimum_Wage"
capture log close
log using "`master'/Code\Doc\tosubmit2/TablaCambiosSample.txt", replace text

/*
reg_emp_bp_tq(`tt')_ejercicio5_ebite
reg_sst_emp_bp_tq(`tt')_ejercicio5_ebite
reg_ie_emp_bp_tq(`tt')_ejercicio5_ebite
reg_iect_emp_bp_tq(`tt')_ejercicio5_ebite
*/
/*====================================================================
                        1: Funciones 
====================================================================*/

// Funciones
cap program drop getfe
program define getfe, rclass
	* City Industry FE: All
	loc cxis="Yes"
	* City Employment: All
	loc cityemps="Yes"
	* Bartik price
	if strmatch("`1'","*bp*") loc bps="Yes"
	else loc bps=""
	* Bartik Quantity
	*if strmatch("`1'","*bq*") loc bqs="Yes"
	*else loc bqs=""
	* City Trends
	if strmatch("`1'","*sst*")  loc csts="Yes" 
	else if strmatch("`1'","*ct*")  loc csts="Yes" 
	else loc csts=""
	* Industry employment
	if strmatch("`1'","*ie*") loc ies="Yes"
	else loc ies=""
	return local cxi="`cxis'"
	return local tfe="Yes"
	return local cityemp="`cityemps'"
	return local bp="`bps'"
	return local cst="`csts'"
	return local ie="`ies'"	
	*return local bq="`bqs'"
end

cap program drop formal
program formal
	syntax, percentil(string) period(string) spec(string) ster(string) tablas(string) wrap(string)
	glo percentil = "`percentil'"
	glo period = "`period'"
	glo spec = "`spec'"
	glo ster = "`ster'"
	glo tablas = "`tablas'"
	glo head ""
	glo botn ""
	glo botr ""
	glo botcxi ""
	glo bottfe ""
	glo botcityemp ""
	glo botbp ""
	glo botcst ""
	glo botie ""
	glo botcfe ""
	glo botbq ""
	foreach ptl in $percentil{
		glo cols ""
		glo betas ""
		glo ses ""
		glo ps ""
		glo colnum=1
		foreach period in $period{
			glo cols "${cols}c"
			loc fw: word 1 of $percentil
			loc count: word count $percentil
			loc lw: word `count' of $percentil
			if `ptl'==`lw'  loc reg="register"
			else loc reg ""
			if `ptl'==`fw' loc r="replace"
			else loc r="append"
			* Header - Column number
			if `ptl'==`fw' {
				glo head "${head} & `period'"
			}
			est use "$ster/`spec'_tq(`period')_ejercicio5_p`ptl'"
			est store `spec'
			glo b:  di %10.4f _b[treat]
			glo se :  di %10.4f _se[treat]
			glo p=e(tp)
			if $p<0.001 glo star "***"
			else if $p<0.05 glo star "**"
			else if $p<0.1 glo star "*"
			else glo star ""
			glo p:  di %10.3f $p
			glo n= e(N)	
			glo betas "${betas} & ${b}${star}"
			glo ses "${ses} & ($se )"
			glo ps "${ps} & [$p ]"
			glo colnum = ${colnum}+1
			if `ptl'==`lw' {
				* Bottom 1 - N
				glo botn "${botn} & $n"
				glo botr "${botr} & $r"
				getfe `pnl'
				glo botcxi "${botcxi} & `r(cxi)'"
				glo bottfe "${bottfe} & `r(tfe)'"
				glo botcityemp "${botcityemp} & `r(cityemp)'"
				glo botbp "${botbp} & `r(bp)'"
				glo botcst "${botcst} & `r(cst)'"
				glo botie "${botie} & `r(ie)'"
			}
						
		}
		if `ptl'==`fw'  loc r "replace" 
		else loc r "append"
		texdoc init "$tablas/formal_`spec'.tex", `r' force
			if `ptl'==`fw' {
				if "`wrap'"=="wrap" {
					tex \documentclass{article}
					tex \usepackage[letterpaper,left=3cm,right=3cm,top=3cm,bottom=3cm]{geometry}
					* tex \usepackage{adjustbox}
					tex \begin{document}
					tex \begin{table}
					tex \caption{`caption'}
					tex \centering
					tex \footnotesize
					* tex \begin{adjustbox}{center}
				}
			tex \begin{tabular}{l${cols}} \hline
			}
			if `ptl'==`fw' tex $head \\\hline
				tex p`ptl' $betas \\
				tex $ses \\
				tex $ps \\	
				if `ptl'==`lw' {
					tex \\\hline
					tex Observations $botn \\
					* tex R squared $botr \\
					tex City x Industry FE $botcxi \\
					* tex City FE $botcfe \\
					tex Time FE $bottfe \\
					tex Bartik Price Shocks $botbp \\
					* tex Bartik quantity shocks $botbq \\
					tex City Specific Trends  $botcst \\
					tex Industry Employment $botie \\
				}
		texdoc close
		}
	texdoc init "$tablas/formal_`spec'.tex", append force
		tex \hline
		tex \end{tabular}
		if "`wrap'"=="wrap"{ 
			tex \end{table}
			tex \end{document}
		}
		texdoc close
		/*
		if "`makepdf'"=="makepdf" {
			cd "$tablas"
			shell pdflatex "$tablas/formal_`spec'.tex"
			! "$tablas/formal_`spec'.pdf"
		}
		*/
end

cap program drop informal
program informal
	syntax, percentil(string) period(string) spec(string) ster(string) tablas(string) wrap(string)
	glo percentil = "`percentil'"
	glo period = "`period'"
	glo spec = "`spec'"
	glo ster = "`ster'"
	glo tablas = "`tablas'"
	glo head ""
	glo botn ""
	* glo botr ""
	glo botcxi ""
	glo bottfe ""
	glo botcityemp ""
	glo botbp ""
	glo botcst ""
	glo botie ""
	*glo botcfe ""
	* glo botbq ""
	foreach ptl in $percentil{
		glo cols ""
		glo betas ""
		glo ses ""
		glo ps ""
		glo colnum=1
		foreach period in $period{
			glo cols "${cols}c"
			loc fw: word 1 of $percentil
			loc count: word count $percentil
			loc lw: word `count' of $percentil
			if `ptl'==`lw'  loc reg="register"
			else loc reg ""
			if `ptl'==`fw' loc r="replace"
			else loc r="append"
			* Header - Column number
			if `ptl'==`fw' {
				glo head "${head} & `period'"
			}
			est use "$ster/`spec'_tq(`period')_ejercicio5_ebite_p`ptl'"
			est store `spec'
			glo b:  di %10.4f _b[treat]
			glo se :  di %10.4f _se[treat]
			glo p=e(tp)
			if $p<0.001 glo star "***"
			else if $p<0.05 glo star "**"
			else if $p<0.1 glo star "*"
			else glo star ""
			glo p:  di %10.3f $p
			glo n= e(N)	
			glo betas "${betas} & ${b}${star}"
			glo ses "${ses} & ($se )"
			glo ps "${ps} & [$p ]"
			glo colnum = ${colnum}+1
			if `ptl'==`lw' {
				* Bottom 1 - N
				glo botn "${botn} & $n"
				glo botr "${botr} & $r"
				getfe `pnl'
				glo botcxi "${botcxi} & `r(cxi)'"
				glo bottfe "${bottfe} & `r(tfe)'"
				glo botcityemp "${botcityemp} & `r(cityemp)'"
				glo botbp "${botbp} & `r(bp)'"
				glo botcst "${botcst} & `r(cst)'"
				glo botie "${botie} & `r(ie)'"
			}
						
		}
		if `ptl'==`fw'  loc r "replace" 
		else loc r "append"
		texdoc init "$tablas/informal_`spec'.tex", `r' force
			if `ptl'==`fw' {
				if "`wrap'"=="wrap" {
					tex \documentclass{article}
					tex \usepackage[letterpaper,left=3cm,right=3cm,top=3cm,bottom=3cm]{geometry}
					* tex \usepackage{adjustbox}
					tex \begin{document}
					tex \begin{table}
					tex \caption{`caption'}
					tex \centering
					tex \footnotesize
					* tex \begin{adjustbox}{center}
				}
			tex \begin{tabular}{l${cols}} \hline
			}
			if `ptl'==`fw' tex $head \\\hline
				tex p`ptl' $betas \\
				tex $ses \\
				tex $ps \\	
				if `ptl'==`lw' {
					tex \\\hline
					tex Observations $botn \\
					* tex R squared $botr \\
					tex City x Industry FE $botcxi \\
					* tex City FE $botcfe \\
					tex Time FE $bottfe \\
					tex Bartik Price Shocks $botbp \\
					* tex Bartik quantity shocks $botbq \\
					tex City Specific Trends  $botcst \\
					tex Industry Employment $botie \\
				}
		texdoc close
		}
	texdoc init "$tablas/informal_`spec'.tex", append force
		tex \hline
		tex \end{tabular}
		if "`wrap'"=="wrap"{ 
			tex \end{table}
			tex \end{document}
		}
		texdoc close
		/*
		if "`makepdf'"=="makepdf" {
			cd "$tablas"
			shell pdflatex "$tablas/formal_`spec'.tex"
			! "$tablas/formal_`spec'.pdf"
		}
		*/

	
end
/*====================================================================
                        2: Formal
====================================================================*/
// Globals
global spec = "reg_emp_bp reg_sst_emp_bp reg_ie_emp_bp reg_iect_emp_bp"
global period = "1999q1 1999q2 1999q3 1999q4"
global percentil= "5 10 15 20 25 30 50"
global wrap = "wrap"
foreach spec in $spec{	
	formal, percentil($percentil) period($period) spec(`spec') ster($ster) tablas($tablas) wrap($wrap)
}

/*====================================================================
                        3: Informal
====================================================================*/
// Globals
global spec = "reg_emp_bp reg_sst_emp_bp reg_ie_emp_bp reg_iect_emp_bp"
global period = "1999q1 1999q2 1999q3 1999q4"
global percentil= "5 10 15 20 25 30 50"
global wrap = "wrap"
foreach spec in $spec{
	informal, percentil($percentil) period($period) spec(`spec') ster($ster) tablas($tablas) wrap($wrap)
}


/*====================================================================
                        4: 
====================================================================*/


/*====================================================================
                        5: 
====================================================================*/


/*====================================================================
                        6: 
====================================================================*/


/*====================================================================
                        7: 
====================================================================*/


/*====================================================================
                        8: 
====================================================================*/


/*====================================================================
                        9: 
====================================================================*/


/*====================================================================
                        10: 
====================================================================*/





log close
exit
/* End of do-file */

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

Notes:
1.
2.
3.


Version Control:


